import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { TimeButton } from "../common/button/TimeButton";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { AutoHeightTileList } from "./AutoHeightTileList";
import { NearbyTeamListCellRenderer } from "./NearbyTeamListCellRenderer";
import { ScrollBarDirection } from "../../../../fl/controls/ScrollBarDirection";
import { NearbyListCellRenderer } from "./NearbyListCellRenderer";
import { DataEvent } from "../../events/DataEvent";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GLabel } from "../../../../com/mui/controls/GLabel";
//class NearbyTeamListBody
    
    export  class NearbyTeamListBody /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */createChildren(): void
        {
            ObjCreate.createLabel(Language.getString(62070), 2, 10, 100, 25, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._quickApplyBtn = new TimeButton(5);
            this._quickApplyBtn.x = 250;
            this._quickApplyBtn.y = 8;
            this._quickApplyBtn.width = 70;
            this._quickApplyBtn.height = 22;
            this._quickApplyBtn.label = Language.getString(62071);
            this._quickApplyBtn.styleName = "Button";
            this._quickApplyBtn.textField.filters = [FilterConst.glowFilter];
            this.addChild(this._quickApplyBtn);
            this._teamList = new AutoHeightTileList();
            this._teamList.styleName = "TileList";
            this.addChild(this._teamList);
            this._teamList.setStyle("cellRenderer", NearbyTeamListCellRenderer);
            this._teamList.move(0, 35);
            this._teamList.direction = ScrollBarDirection.VERTICAL;
            this._teamList.setSize(328, 100);
            this._teamList.columnWidth = 328;
            this._teamList.rowHeight = 38;
            this._noTeamLabel = ObjCreate.createLabel(Language.getString(62072), 2, 30, 100, 25, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._maxProcess = ObjCreate.createLabel(Language.getString(60463), 190, 30, 100, 25, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._quickInviteBtn = new TimeButton(5);
            this._quickInviteBtn.x = 250;
            this._quickInviteBtn.y = 30;
            this._quickInviteBtn.width = 70;
            this._quickInviteBtn.height = 22;
            this._quickInviteBtn.label = Language.getString(62073);
            this._quickInviteBtn.styleName = "Button";
            this._quickInviteBtn.textField.filters = [FilterConst.glowFilter];
            this.addChild(this._quickInviteBtn);
            this._playerList = new AutoHeightTileList();
            this._playerList.styleName = "TileList";
            this.addChild(this._playerList);
            this._playerList.setStyle("cellRenderer", NearbyListCellRenderer);
            this._playerList.direction = ScrollBarDirection.VERTICAL;
            this._playerList.setSize(328, 100);
            this._playerList.columnWidth = 328;
            this._playerList.rowHeight = 38;
            return;
        }

        /* internal  */addListeners(): void
        {
            this._teamList.addEventListener(flash.events.Event.CHANGE, this.onListChange);
            this._playerList.addEventListener(flash.events.Event.CHANGE, this.onListChange);
            this._quickApplyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._quickInviteBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            return;
        }

        /* internal  */onListChange(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._teamList:
                {
                    if (this._teamList.selectedItem) 
                    {
                        this._playerList.selectedIndex = -1;
                    }
                    this.selectedChange();
                    break;
                }
                case this._playerList:
                {
                    if (this._playerList.selectedItem) 
                    {
                        this._teamList.selectedIndex = -1;
                    }
                    this.selectedChange();
                    break;
                }
            }
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget;
            switch (loc1) 
            {
                case this._quickApplyBtn:
                {
                    this.dispatchEvent(new DataEvent(GModuleEvent.Event_QuickApply, this.isCross, false, true, false));
                    break;
                }
                case this._quickInviteBtn:
                {
                    this.dispatchEvent(new DataEvent(GModuleEvent.Event_QuickInvite, this.isCross, false, true, false));
                    break;
                }
            }
            return;
        }

        public updateListDatas(arg1: Array<any>, arg2: Array<any>, arg3: Boolean): void
        {
            this._teamList.dataProvider = new DataProvider(arg1);
            this._playerList.dataProvider = new DataProvider(arg2);
            this._maxProcess.visible = arg3;
            this.updateLocation();
            return;
        }

        public get selectedType(): string
        {
            if (this._teamList.selectedItem) 
            {
                return NearbyTeamListBody.selectedType_team;
            }
            if (this._playerList.selectedItem) 
            {
                return NearbyTeamListBody.selectedType_player;
            }
            return NearbyTeamListBody.selectedType_none;
        }

        /* internal  */onListResize(): void
        {
            this.dispatchEvent(new Object /* flash.events.Event */(NearbyTeamListBody.NearbyTeamListBodyResize));
            return;
        }

        public get selectedTeamItem(): Object
        {
            return this._teamList.selectedItem;
        }

        public get selectedPlayerItem(): Object
        {
            return this._playerList.selectedItem;
        }

        /* internal  */updateLocation(): void
        {
            var loc1;
            this._quickInviteBtn.y = loc1 = this._teamList.height + 38;
            this._noTeamLabel.y = loc1;
            this._maxProcess.y = this._noTeamLabel.y + 10;
            this._playerList.y = this._noTeamLabel.y + 25;
            this.onListResize();
            return;
        }

        /* internal  */selectedChange(): void
        {
            this.dispatchEvent(new Object /* flash.events.Event */(NearbyTeamListBody.SelectedChange));
            return;
        }

        public /* override */ get height(): number
        {
            return this._teamList.height + this._playerList.height + 60;
        }

        public static /* const */SelectedChange: string="nearbyTeamSelectedChange";

        public static /* const */NearbyTeamListBodyResize: string="NearbyTeamListBody.NearbyTeamListBodyResize";

        public static /* const */selectedType_team: string="NearbyTeamListBody.selectedType_team";

        public static /* const */selectedType_player: string="NearbyTeamListBody.selectedType_player";

        public static /* const */selectedType_none: string="NearbyTeamListBody.selectedType_none";

        /* internal */ /* var */_quickApplyBtn: TimeButton;

        /* internal */ /* var */_quickInviteBtn: TimeButton;

        /* internal */ /* var */_teamList: AutoHeightTileList;

        /* internal */ /* var */_playerList: AutoHeightTileList;

        /* internal */ /* var */_noTeamLabel: GLabel;

        /* internal */ /* var */_maxProcess: GLabel;

        public /* var */isCross: Boolean;
    }
